<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>留言板</title>

    <!-- Bootstrap core CSS -->
    <link href="<?php echo __PUBLIC__; ?>/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="jumbotron.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <form class="navbar-form navbar-right" id="loginform">

            <?php if(isset($_SESSION['username'])){ ?>
                <button type="button" class="btn btn-success"  id="login"><?php echo $_SESSION['username'];  ?></button>
              <a href="loginout.php"  class="btn btn-success">退出</a>
            <?php }else{ ?>

            
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control" name="email">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control" name="password">
            </div>
            <button type="button" class="btn btn-success"  id="login">登录</button>
            <a href="reg.php"  class="btn btn-success">注册</a>


            <?php } ?>
            
          </form>
        </div><!--/.navbar-collapse -->
      </div>
    </nav>
 

    <!-- Main jumbotron for a primary marketing message or call to action -->

    <?php $colors = ['alert alert-danger','alert alert-success','alert alert-info','alert alert-warning']; ?>
  
    <div class="container" style="padding-top:100px;">
    	<?php foreach ($data as $k => $v) { ?>
	      <div class="<?php echo $colors[array_rand($colors)] ?>" role="alert">
	        <strong><?php echo $v['username'] ?></strong> <?php echo $v['content'] ?>(<?php echo Ftime($v['ctime']) ?>)
	        <div style="float:right">
	        	<h4>
	        	<a href="./index.php?m=index&c=index&a=del&id=<?php echo $v['mid']; ?>" class="label label-danger">删除</a>
				<a href="./edit.php?id=<?php echo $v['mid']; ?>>" class="label label-info">修改</a>
				</h2>
	        </div>
	      </div>

      	<?php } ?>
      <form class="form-inline" action="./add.php" method="post">
		  <div class="form-group">
		    <label class="sr-only" for="exampleInputEmail3">用户名</label>
		    <input type="text" class="form-control" id="exampleInputEmail3" name="username" placeholder="用户名">
		  </div>
		  <button type="submit" class="btn btn-success">留言</button>

		  <div class="" style="margin-top:20px;">
		  	<textarea style="width:100%" class="form-control" rows="5" name="content"></textarea>
		  </div>
		  
		</form>

      <hr>

      <footer>
        <p>&copy; 2016 Company, Inc.</p>
      </footer>
    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>

    <script type="text/javascript">

        $(function  () {

          $('#login').click(function(event) {
                formdata = $('#loginform').serialize();

                console.log(formdata);

                $.ajax({
                  url: './checklogin.php',
                  type: 'post',
                  dataType: 'json',
                  data: formdata,
                })
                .done(function(res) {
                    if(res.error==1){
                      alert(res.info);
                    }else{
                      alert(res.info);
                      location.reload();
                    }
                })
                .fail(function() {
                  console.log("error");
                })
          });
        })

    </script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>
